<?php $show_dialog = true;
include THEMES_PATH . 'public/before_body2.phtml';?>
<link href="/statics/front/css/cart.css" rel="stylesheet">
</head>
<body>
<?php include THEMES_PATH . 'public/header2.phtml';?>
<div class="main-width heading">
  <strong><?php echo L('editorderinfo');?></strong>
</div>
<form name="checkoutForm" id="checkoutForm" method="post" action="<?php echo url('order/order_edit', 'oid='.$orderInfo['id']); ?>">
  <input type="hidden" name="goods_amount" id="goods_amount" value="<?php echo isset($orderInfo['product_amount']) ? $orderInfo['product_amount'] : '0'; ?>" />
  <input type="hidden" name="fromcart" value="<?php echo isset($fromcart) ? $fromcart : 0?>" />
  <input type="hidden" name="ordertoken" value="<?php echo isset($ordertoken) ? $ordertoken : 0?>" />
  <input type="hidden" name="delivery_cid" id="delivery_cid" value="<?php echo isset($orderInfo['delivery_cid']) ? $orderInfo['delivery_cid'] : '0'; ?>" />
  <input type="hidden" name="delivery_pid" id="delivery_pid" />
  <input type="hidden" name="shipping_fee" id="input_shipping_money" value="<?php echo isset($orderInfo['shipping_fee']) ? $orderInfo['shipping_fee'] : '0'; ?>" />
  <input type="hidden" name="payment_fee" id="input_payment_money" value="<?php echo isset($orderInfo['payment_fee']) ? $orderInfo['payment_fee'] : '0'; ?>" />
  <input type="hidden" name="surplus_money" id="input_surplus_money" value="<?php echo isset($orderInfo['surplus_money']) ? $orderInfo['surplus_money'] : '0'; ?>" />
  <input type="hidden" name="integral_money" id="input_integral_money" value="<?php echo isset($orderInfo['integral_money']) ? $orderInfo['integral_money'] : '0'; ?>" />
  <input type="hidden" name="adelivery_address_id" id="adelivery_address_id" value="0" />
  <div class="main-width">
    <dl class="address-fields col-md-12 mb2x">
      <dt class="caption"><i class="serial-num">1</i><?php echo L('delivery_address')?></dt>

      <dd class="col-md-12">
        <label><?php echo L('fristname')?>: <input type="text" name="delivery_first_name" required id="delivery_first_name" value="<?php echo isset($orderInfo['delivery_first_name']) ? $orderInfo['delivery_first_name'] : '';?>" /></label>
      </dd>
      <dd class="col-md-12">
        <label><?php echo L('state')?>: <input type="text" name="delivery_province" required id="delivery_province" value="<?php echo isset($orderInfo['delivery_province']) ? $orderInfo['delivery_province'] : '';?>" /></label>
      </dd>
      <dd class="col-md-12">
        <label><?php echo L('city')?>: <input type="text" name="delivery_city" required id="delivery_city" value="<?php echo isset($orderInfo['delivery_city']) ? $orderInfo['delivery_city'] : '';?>" /></label>
      </dd>
      <dd class="col-md-12">
        <label><?php echo L('_STREET_LINE1_');?>: <input type="text" name="delivery_address" required id="delivery_address" value="<?php echo isset($orderInfo['delivery_address']) ? $orderInfo['delivery_address'] : '';?>" /></label>
      </dd>
      <dd class="col-md-12">
        <label><?php echo L('_STREET_LINE2_');?>: <input type="text" name="delivery_address2" required id="delivery_address2" value="<?php echo isset($orderInfo['delivery_address2']) ? $orderInfo['delivery_address2'] : '';?>" /></label>
      </dd>
      <dd class="col-md-12">
        <label><?php echo L('phone')?>: <input type="text" name="delivery_phone" required id="delivery_phone" value="<?php echo isset($orderInfo['delivery_phone']) ? $orderInfo['delivery_phone'] : '';?>" /></label>
      </dd>
      <dd class="col-md-12">
        <label><?php echo L('email')?>: <input type="text" name="delivery_email" required id="delivery_email" value="<?php echo isset($orderInfo['delivery_email']) ? $orderInfo['delivery_email'] : '';?>"/></label>
      </dd>
    </dl>
    <dl class="definition-list shipping-method js-shipping-method">
      <dt class="caption"><input type="hidden" name="shipping_method" value="<?php echo $orderInfo['shipping_method'];?>" /><i>2</i><?php echo L('shipping_method')?></dt>
      <?php
         if(isset($shippingList) && $shippingList):
         $i=0;
            foreach ($shippingList as $key=>$shipping):
             if (!$shipping['status']) continue;
                $i++;
      ?>
      <dd<?php if ($shipping['name'] == $orderInfo['shipping_method']){?> class="selected" <?php } ?> data-info="<?php echo $shipping['name'];?>">
        <p class="text"><?php echo isset($shipping['title']) ? $shipping['title'] : null;?></p>
        <p class="align-center title"><?php if ($key==0){?><?php echo L('_STANDARD_');?><?php }else{?><?php echo L('_EXPEDITED_');?><?php }?></p>
        <p><?php echo $shippingList[$key]['description'];?></p>
        <i class="mark"></i>
      </dd>
      <?php
          endforeach;
        endif;
      ?>
    </dl>
    <dl class="definition-list payment-method js-payment-method">
      <dt class="caption"><input type="hidden" name="payment_method" value="<?php echo $orderInfo['payment_method'];?>" /><i>3</i><?php echo L('payment_method')?></dt>
      <?php
        if(isset($paymentList) && $paymentList):
        $i=1;
        foreach ($paymentList as $k => $payment) :
         if (!$payment['status']) continue;
      ?>
      <dd<?php if ($payment['name'] == $orderInfo['payment_method']){?> class="selected" <?php } ?> data-info="<?php echo $payment['name'];?>">
        <p class="text"><?php if($payment['name'] =="Visabill"){echo L('_credit_');}elseif($payment['name'] == "Paypal"){echo L('_paypal_');}elseif($payment['name'] == "Worldpay"){echo L('_worldpay_');}elseif($payment['name'] == "Alipay"){echo L('_alipay_');};?>></p>
        <img src="/statics/front/images/cart/<?php if($payment['name'] =="Visabill"){echo "visa";}elseif($payment['name'] == "Paypal"){echo "paypal";}elseif($payment['name'] == "Worldpay"){echo "worldpay";}elseif($payment['name'] == "Alipay"){echo "alipay";};?>.png" alt="<?php echo isset($payment['name']) ? $payment['name'] : null ;?>" />
        <i class="mark"></i>
      </dd>
      <?php
        $i++;
        endforeach;
        endif;
      ?>
    </dl>
    <p class="align-right" style="margin-bottom:7%;">
      <input type="submit" name="dosubmit" value="<?php echo L('submit');?>" class="btn btn-middle" />
    </p>
  </div>
</form>
<?php include THEMES_PATH . 'public/footer2.phtml';?>
<?php include THEMES_PATH . 'public/after_body.phtml';?>
<script src="/statics/front/js/scripts/cart.js"></script>
<script>
$(function() {
  <?php if(!empty($addressList)){?>
  getCartAddress();
  <?php }?>
  getshippingmoney();

  $('#select_countries').change(function() { //选择国家
    $(this).prev().text($(this).find('option:selected').text());
    getshippingmoney();
  });

  var $checkoutForm = $('#checkoutForm');
  $checkoutForm.validate({ //发货地址相关字段验证
    errorElement: 'p',
    submitHandler: function(form) {
      form.submit();
    },
    errorPlacement: function(error, element) {
      element.after(error).parent().addClass('error');
    },
    success: function(label) {
      label.parent().removeClass('error');
    },
    rules: {
      delivery_cid:{
        required: true,
        min:1
      },
      delivery_phone: {
        required: true
      },
      delivery_email: {
        required: true,
        email: true
      }
    },
    messages: {
      delivery_email: {
        requried: $checkoutForm.find('input[name=delivery_email]').attr('title'),
        email: $checkoutForm.find('input[name=delivery_email]').data('email')
      }
    }
  });

  $('.js-shipping-method').find('dd').on('click', function() { //选择发货地址
    var $this = $(this);
    $this.parent().find('dt > input[type=hidden]').val($this.data('info'));
    $this.addClass('selected').siblings().removeClass('selected');
    getshippingmoney();
  });

  $('.js-payment-method').find('dd').on('click', function() { //选择支付方式
    var $this = $(this);
    $this.parent().find('dt > input[type=hidden]').val($this.data('info'));
    $this.addClass('selected').siblings().removeClass('selected');
    getPaymentMoney();
  });
});
</script>